package com.musicapp;

import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class List extends Dialog {
    java.util.List<SongModel> songList = FirstFragment.songList;
    private RecyclerView recyclerView;
    private ListAdapter adapter;

    public List(@NonNull Context context) {
        super(context);
        initDialog();
    }

    private void initDialog() {
        setContentView(R.layout.list);
        setCancelable(true);
        setCanceledOnTouchOutside(true);

        // 获取屏幕宽度
        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindow().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        int screenWidth = displayMetrics.widthPixels;

        // 设置 Dialog 的宽度
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = screenWidth;
        getWindow().setAttributes(params);

        recyclerView = findViewById(R.id.listout);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new ListAdapter();

//        列表删除功能
        adapter.setmOnItemClickListen(new ItemAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                adapter.removeItem(position);
            }
        });
        recyclerView.setAdapter(adapter);
    }
}